define(["../../carrys/md5","../../../../js/lib/other/sweet-alert"],function() {
    return ['$scope','$location', '$interval','$timeout','bizProxy', function($scope,$location,$interval,$timeout,bizProxy) {
		$scope.$emit("top-show",'true');//顶部显示
    	$scope.$emit('menuTypeLight','mine'); 	//控制底部menu高亮
    	$scope.$emit('bub-menu','true'); 	//隐藏底部menu
    	$scope.$emit('flag-tag','10-1');//显示底部文字
    	
    	$scope.mobileNo = "",$scope.authCode = "",$scope.isbt_disabled = false, $scope.isactive = false, $scope.countdown = 60;
    	
    	var timeOutId;
    	var tempCheckNo = "";
    	//点击获取验证码
    	$scope.getAuthCode = function(){
    		if(! _SYT_util.isValidNo($scope.mobileNo)){
    			$scope.$emit("promptAlertMsg","手机号无效");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    			return;
    		}
    		
    		$scope.isbt_disabled = true;
			startGetAuthCode();
    	}
    	
    	
    	//监听是否需要高亮下一步
    	$scope.$watch('authCode', function() {
    		if(($scope.authCode + '').length > 0){
    			changeStyle();
    		}
		});
    	$scope.$watch('mobileNo', function() {
    		if(($scope.mobileNo).length > 0){
    			if(($scope.mobileNo).length == 11){
        			$scope.isClick = true;
        		}else{
        			$scope.isClick = false;
        		}
        		changeStyle();
    		}
		});
    	
    	//去下一步去登陆
    	$scope.goNext = function(){
    		//验证验证码
    		if(tempCheckNo == hex_md5($scope.authCode+"")){
    			transData.mobileNo = $scope.mobileNo;
    			transData.mobileCheckNo = $scope.authCode+"";
        		goLogin();
    		}else{
    			$scope.$emit("promptAlertMsg","验证码错误");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    				transData.mobileCheckNo = "";
					$scope.authCode = "";
    			},transData.promptTime);
    		}
    	}
    	
    	//切换样式
    	function changeStyle(){
    		if(($scope.mobileNo).length == 11 && ($scope.authCode + '').length == 6){
				$scope.isactive = true;
			}else{
				$scope.isactive = false;
			}
    	}
    	
    	//去登陆
    	function goLogin(){
    		transData.mobileNo = $scope.mobileNo;
    		
    		var headerInfo = {},sendData = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	sendData.loginType = "checkNo";
    		sendData.mobileNo = $scope.mobileNo;
    		sendData.password = "";
    		sendData.mobileCheckNo = $scope.authCode;
    		$scope.$emit("loadingChangeTpr",true);
    		bizProxy.queryProxyBizData("userLogin",headerInfo,sendData,
    				function(tempData){//SUCCESS
    					localStorage.setItem("fireFlySessionId",tempData.sessionId+"");
    					$scope.$emit("loadingChangeTpr",false);
    					console.log(tempData.body)
    					var body = JSON.parse(tempData.body);
						transData.mobileNo = body.mobileNo;
						transData.sessionId = tempData.sessionId;
						transData.userId = body.userId;
						transData.userType = body.userType;
						resultData.loginUserData = body;
						$timeout(function(){
							if(transData.gotoUrl != ""){
								$location.path("/login").replace();//想改变当前 URL 而不创建新的历史记录的话
								if(transData.gotoUrl == "/fireLoanForm"){
									transData.gotoUrl = "";
									$scope.$emit('goNext',"/fireLoanForm");
								}else if(transData.gotoUrl == "/caseSrcLib"){
									transData.gotoUrl = "";
									$scope.$emit('goNext',"/caseSrcLib/2");
								}else if(transData.gotoUrl == "/caseProfile"){
									transData.gotoUrl = "";
									$scope.$emit('goNext',"/caseProfile");
								}
							}else{
								if(transData.userType === '1'){
	        						$scope.$emit('goNext',"/mineLs");
	        					}else if(transData.userType === '0'){
	        						$scope.$emit('goNext',"/minePt");
	        					}
							}
							
						},0);
		    		},function(data){//FAIL
		    			$scope.$emit("loadingChangeTpr",false);
	    				if(data != ""){
	    					if(data.errorCode == ERROR_CODE.notExist){
	    						$scope.$emit("promptAlertMsg",data.errorMsg);
	    						$scope.$emit("showCollect",true);
	    						$timeout(function(){
	    							$scope.$emit("showCollect",false);
	    							transData.password = "",transData.mobileNo = "";
	    						},transData.promptTime);
							}else if(data.errorCode == ERROR_CODE.pwdNotMatch){
								$scope.$emit("promptAlertMsg",data.errorMsg);
								$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
								},transData.promptTime);
							}else{
								$scope.$emit("promptAlertMsg","连接超时");
								$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
									transData.password = "",transData.mobileNo = "";
								},transData.promptTime);
							}
	    				}else{
	    					$scope.$emit("loadingChangeTpr",false);
	    					$scope.$emit("promptAlertMsg","连接超时");
	    					$scope.$emit("showCollect",true);
	    					$timeout(function(){
	    						$scope.$emit("showCollect",false);
	    						transData.password = "",transData.mobileNo = "";
	    						$scope.$emit("goNext","/mine");
	    					},transData.promptTime);
	    				}
						
		    		});
    	}
    	
    	
    	//开始获取验证码
    	function startGetAuthCode(){
    		startCountDown();
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
    		bizInfo.mobileNo = $scope.mobileNo;
    		bizProxy.queryProxyBizData("sendCheckNo",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
    					tempCheckNo = tempData.body;
		    },function(){});
    	}
    	
    	
    	//开始倒计时
        function startCountDown(){
     	   timeOutId = $interval(function(){
                if (--$scope.countdown == 0){
             	   stopCountDown();
             	   $scope.countdown = 60;
             	   $scope.isbt_disabled = false;
                }
            }, 1000);
        }
        
        //停止倒计时
        function stopCountDown() {
     	   $interval.cancel(timeOutId);
        }
        
      //当键盘被销毁的时候
        $scope.$on("$destroy", function() {
	      	stopCountDown();
	    });
    	
        $scope.$apply();
    }];
});